﻿using System;
using System.ComponentModel;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using Microsoft.SharePoint;
using Microsoft.SharePoint.WebControls;

namespace PaulBeck.Timesheet.WebParts.Week
{
    [ToolboxItemAttribute(false)]
    public class Week : WebPart, BOL.Interface.IWeekId
    {

        public BOL.Interface.IResource provider;
        Control control;

        // Visual Studio might automatically update this path when you change the Visual Web Part project item.
        private const string _ascxPath = @"~/_CONTROLTEMPLATES/PaulBeck.Timesheet.WebParts/Week/WeekUserControl.ascx";

        protected override void CreateChildControls()
        {
            control = Page.LoadControl(_ascxPath);
            Controls.Add(control);
        }

        [ConnectionConsumer("ResourceIdConsumer", "ResourceIdConsumer")]
        public void ReceiveProvider(BOL.Interface.IResource p)
        {
            EnsureChildControls();
            provider = p;
            if (provider.GetResourceId != 0)
            {
                ((WeekUserControl)control).DisplayWeeks(provider.GetResourceId);
            }
        }

        public int GetWeekId
        {
            get
            {
                WeekUserControl cuc = (WeekUserControl)control;
                return cuc.GetWeekId();
            }
        }

        [ConnectionProvider("WeekId", "WeekId", AllowsMultipleConnections = true)]
        public BOL.Interface.IWeekId GetWeek()
        {
            return this;
        }

    }
}
